package org.yagnus.ml.ie;

import org.yagnus.interfaces.Resettable;

/**
 * This class encapsulates the concept of precision and recall performance by storing the confusion
 * matrix for an extraction task.
 * 
 * In particular, we store separate set of statistics relative to the extraction and then also
 * relative to the ground truth, this allows us to correctly compute recall when there are duplicate
 * or overlapping ground truths.
 * 
 * @author hc.busy
 * 
 *         TODO: implement Freezable
 * 
 */
public abstract class PrecisionRecall implements Resettable {

    public abstract double getTruePositive();

    public abstract double getFalsePositive();

    public abstract double getTrueNegative();

    public abstract double getFalseNegative();

    public abstract double getRecalled();

    public abstract double getTruthCount();

    public abstract double getExtractionCount();

    public double getRecallRate() {
        if (getTruthCount() == 0) {
            return 1; // by definition anything out of 0 is 100% recall
        }
        return getRecalled() / getTruthCount();
    }

    public double getPrecisionRate() {
        if (getExtractionCount() == 0) {
            return 1; // by definition if we didn't extract anything, then all
                      // of them are right
        }
        return getTruePositive() / getExtractionCount();
    }
}
